package yjj.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import yjj.system.entity.UserDept;
import yjj.system.mapper.UserDeptMapper;
import yjj.system.service.UserDeptService;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class UserDeptServiceImpl extends ServiceImpl<UserDeptMapper, UserDept> implements UserDeptService {

    @Override
    public List<String> findDeparts(List<String> deptIds) {
        if (deptIds == null || deptIds.isEmpty()) {
            return null;
        }
        LambdaQueryWrapper<UserDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(UserDept::getDeptId, deptIds);
        List<UserDept> userDeptList = this.list(queryWrapper);
        List<String > userIds= userDeptList.stream().map(UserDept::getUserId).collect(Collectors.toList());
        return userIds;
    }

    @Override
    public List<String> getDeptIdsByUserId(String userId, String tenantId) {
        LambdaQueryWrapper<UserDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserDept::getUserId, userId)
                .eq(UserDept::getTenantId, tenantId);
        List<UserDept> userDeptList = this.list(queryWrapper);
        return userDeptList.stream().map(UserDept::getDeptId).collect(Collectors.toList());
    }
}
